import { modal } from 'vue-strap'
import { showMsg, swapInvesterbeta } from '../../../../../vuex/action.js'

export default {
  data() {
    return {
      showSwapPortfolioModal: false,
      groupId1: '',
      groupId2: ''
    }
  },
  methods: {
    trim(inStr) {
      return inStr.replace(/(^ +)|( +$)/g, '')
    },
    checkValid() {
      if (this.groupId1.length === 0) {
        return '请输入组合ID1'
      } else if (this.groupId2.length === 0) {
        return '请输入组合ID2'
      }
    },
    swapInvesterbeta() {
      let validMsg = this.checkValid()
      if (validMsg) {
        return this.xShowMsg({
          type: 'danger',
          content: validMsg
        })
      }

      this.xSwapInvesterBeta({
        id1: this.groupId1,
        id2: this.groupId2,
        type: this.payType
      }).then((res) => {
        this.$els.addForm.reset()
        this.showSwapPortfolioModal = false
        this.$dispatch('on_refresh_list')
      })
    }
  },
  components: {
    modal: modal
  },
  vuex: {
    getters: {
      payType: state => state.payType
    },
    actions: {
      xShowMsg: showMsg,
      xSwapInvesterBeta: swapInvesterbeta
    }
  }
}
